const mysql = require('mysql2/promise');
require('dotenv').config();

const dbConfig = {
  host: '192.168.0.101',
  port: 3306,
  user: 'root',
  password: 'Asdf123456@',
  database: 'lotus_company',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
};

const pool = mysql.createPool(dbConfig);

// 测试数据库连接
async function testConnection() {
  try {
    const connection = await pool.getConnection();
    console.log('✅ MySQL连接成功');
    connection.release();
    return true;
  } catch (error) {
    console.error('❌ MySQL连接失败:', error.message);
    return false;
  }
}

module.exports = { pool, testConnection };